const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');

Page({

	data: {
		income: '',
		settlement: true,
		date: '2022-08',
		itype: 1,
		attendCount: 0,
		attendMoney: 0,
		totalType: 0 //0=累计统计，1=按月统计
	},
	bindDateChange: function(e) {
		// console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
			date: e.detail.value
		});
		this.getIncome();
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.toToday();
		var income = options.income;
		var totalType = this.data.totalType;
		var date = this.data.year + '-' + this.data.month;
		if (income == 'month') {
			totalType = 1;
		}
		this.setData({
			income: options.income,
			totalType: totalType,
			date: date
		});
		this.getIncome();
	},
	checkstatus(e) {
		var itype = e.currentTarget.dataset.type; //结算状态
		this.setData({
			settlement: JSON.parse(e.currentTarget.dataset.settlement),
			itype: itype
		});
		this.getIncome();
	},
	getIncome() {

		var that = this;
		http.httpPost(config.getIncome, {
			itpye: that.data.itype,
			totalType: that.data.totalType,
			dateTime: that.data.date
		}, function(e) {
			if (e.code == 1) {
				that.setData({
					attendCount: e.data.attendCount,
					attendMoney: e.data.attendMoney
				});
			}
		});
	},
	toToday() {
		let year = new Date().getFullYear(),
			month = new Date().getMonth() + 1,
			day = new Date().getDate();
		if (month <= 9) {
			month = '0' + month;
		}
		if (day <= 9) {
			day = '0' + day;
		}

		this.setData({
			year,
			day,
			month
		})
	},
	onReady() {
		if (!app.login()) {
			return;
		}
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
